<template>
  <!-- 添加或修改出货通知单对话框 -->
  <el-dialog :title="title" :visible.sync="open" width="100%" append-to-body :close-on-click-modal="false" v-dialogDrag>
    <div class="app-container" style="display: flex;">
      <el-row style="width: 100%;">
        <el-col :span="24">
          <el-card class="box-card" style="margin-left: 10px;">
            <el-form :model="queryParams" ref="queryForm" size="small" v-show="showSearch" :inline="true"
              label-width="98px">
              <el-form-item label="买方" prop="customerId" size="mini">
                <el-select style="width: 100%;" v-model="queryParams.params['customId']" placeholder="请选择买方" filterable
                  @change="selectCustomerQuery" clearable>
                  <el-option v-for="dict in dict.type.goods_customer" :key="dict.value" :label="dict.label"
                    :value="dict.value" />
                </el-select>
              </el-form-item>
              <el-form-item label="订单编号" prop="projectNo" size="mini">
                <!-- <el-select v-model="projectNos" placeholder="请选择订单编号" filterable clearable  multiple>
                  <el-option v-for="item in orderList" :key="item.code" :label="item.code" :value="item.code" />
                </el-select> -->
                <el-select v-model="projectNos" multiple filterable remote reserve-keyword placeholder="请输入订单编号"
                  :remote-method="search" :loading="loading3">
                  <el-option v-for="item in options3" :key="item.code" :label="item.code" :value="item.code">
                  </el-option>
                </el-select>
              </el-form-item>
              <el-form-item label="产品编码" prop="goodsCode" size="mini">
                <el-input v-model="queryParams.goodsCode" style="width: 160px;" placeholder="请输入产品编码" clearable
                  @keyup.enter.native="handleQuery" />
              </el-form-item>
              <el-form-item label="产品名称" prop="goodsName" size="mini">
                <el-input v-model="queryParams.goodsName" style="width: 160px;" placeholder="请输入产品名称" clearable
                  @keyup.enter.native="handleQuery" />
              </el-form-item>
              <el-form-item label="产品型号" prop="goodModel" size="mini">
                <el-input v-model="queryParams.goodModel" style="width: 160px;" placeholder="请输入产品型号" clearable
                  @keyup.enter.native="handleQuery" />
              </el-form-item>
              <el-form-item label="客户编码" prop="customerCode" size="mini">
                <el-input v-model="queryParams.params['customerCode']" style="width: 160px;" placeholder="请输入客户编码"
                  clearable @keyup.enter.native="handleQuery" />
              </el-form-item>
              <!-- <el-form-item label="项目单位" prop="companyName" size="mini">
                <el-input v-model="queryParams.params['companyName']" style="width: 160px;" placeholder="请输入项目单位"
                          clearable
                          @keyup.enter.native="handleQuery"/>
              </el-form-item> -->
              <el-form-item label="工程名称" prop="gongchengName" size="mini">
                <el-input v-model="queryParams.gongchengName" style="width: 160px;" placeholder="请输入工程名称" clearable
                  @keyup.enter.native="handleQuery" />
              </el-form-item>
              <el-form-item label="下单日期" prop="orderDate" size="mini">
                <el-date-picker v-model="queryParams.params['orderDate']" style="width: 160px;" placeholder="请选择下单日期"
                  type="date" value-format="yyyy-MM-dd" clearable @keyup.enter.native="handleQuery" />
              </el-form-item>
              <el-form-item label="业务员" prop="salesmanName" size="mini">
                <el-input v-model="queryParams.params['salesmanName']" style="width: 160px;" placeholder="请输入业务员"
                  clearable @keyup.enter.native="handleQuery" />
              </el-form-item>
              <el-form-item label="制单人" prop="goodModel" size="mini">
                <el-input v-model="queryParams.params['createName']" style="width: 160px;" placeholder="请输入制单人"
                  clearable @keyup.enter.native="handleQuery" />
              </el-form-item>
              <el-form-item label="合同收货人" prop="deliveryPerson" size="mini">
                <el-input v-model="queryParams.deliveryPerson" style="width: 160px;" placeholder="请输入合同收货人" clearable
                  @keyup.enter.native="handleQuery" />
              </el-form-item>

              <el-form-item>
                <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
                <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
                <el-button type="primary" size="mini" @click="submitForm">添 加</el-button>
              </el-form-item>
              <el-form-item label="已勾选合计" prop="goodModel" v-if="selectedRowsGoodsSale.length > 0">
                <span> {{selectedRowsGoodsSale.reduce((acc, row) => acc + row.sendCount, 0)}}</span>
              </el-form-item>
            </el-form>

            <el-form ref="formList" :model="form" label-width="120px">
              <el-table border v-loading="loading" :data="columns" @selection-change="handleSelectionChangeGoodsSale"
                show-summary :summary-method="getSummaries" max-height="700px" @sort-change="handleSortChange">
                <el-table-column type="selection" width="60" align="center" fixed="left" />
                <el-table-column sortable label="订单编号" align="center" prop="projectNo" />
                <el-table-column sortable label="买方" align="center" prop="order.customName" />
                <!-- <el-table-column sortable label="项目单位" align="center" prop="order.companyName"/> -->
                <el-table-column sortable label="工程名称" align="center" prop="gongchengName" />
                <el-table-column sortable label="发货状态" align="center" prop="isfahuo" show-overflow-tooltip>
                  <template slot-scope="scope">
                    <dict-tag :options="dict.type.yifahuo_status" :value="scope.row.isfahuo" />
                  </template>
                </el-table-column>
                <el-table-column sortable label="下单日期" align="center" prop="order.orderDate" />
                <el-table-column sortable label="产品编码" align="center" prop="goodsCode" />
                <el-table-column sortable label="产品名称" align="center" prop="goodsName" />
                <el-table-column sortable label="产品型号" align="center" prop="goodModel" />
                <el-table-column label="订单数量" align="center" prop="orderCount" width="80px" />
                <!--                <el-table-column label="剩余发货" align="center" prop="fahuoShengyu" show-overflow-tooltip width="80px"-->
                <!--                                 fixed="right"/>-->
                <el-table-column label="发货数量" align="center" prop="sendCount" show-overflow-tooltip width="150"
                  fixed="right">
                  <template slot-scope="scope">
                    <el-input-number size="mini" :max="scope.row.orderCount" :precision="2" v-model="scope.row.sendCount"></el-input-number>
                  </template>
                </el-table-column>
                <el-table-column label="备注" align="center" prop="remark" show-overflow-tooltip fixed="right">
                  <template slot-scope="scope">
                    <el-input v-model="scope.row.remark"></el-input>
                  </template>
                </el-table-column>
              </el-table>
            </el-form>
            <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum"
              :page-sizes="[50, 100, 300, 500, 1000]" :limit.sync="queryParams.pageSize" @pagination="getList" />
          </el-card>
          <el-row>
            <el-col :span="24">
              <el-card class="box-card" style="margin-left: 10px;margin-top: 10px;">
                <el-form ref="form" :model="form" :rules="rules" label-width="98px" :inline="true">
                  <el-form-item label="发货单编号" prop="nos">
                    <el-input v-model="form.nos" placeholder="保存后自动生成" disabled />
                  </el-form-item>
                  <el-form-item label="买方" prop="kehuId">
                    <el-select v-model="form.kehuId" placeholder="请选择买方" filterable @change="selectCustomer" clearable
                      style="width: 100%">
                      <el-option v-for="dict in dict.type.goods_customer" ref="myselectCustomer" :key="dict.value"
                        :label="dict.label" :value="dict.value" />
                    </el-select>
                  </el-form-item>
                  <el-form-item label="联系人" prop="linkman">
                    <el-input v-model="form.linkman" placeholder="请输入联系人" />
                  </el-form-item>
                  <el-form-item label="联系电话" prop="linktel">
                    <el-input style="width: 100%;" v-model="form.linktel" placeholder="请输入联系电话" />
                  </el-form-item>
                  <el-form-item label="发货日期" prop="fahuoDate">
                    <el-date-picker style="width: 100%;" clearable v-model="form.fahuoDate" type="date"
                      value-format="yyyy-MM-dd" placeholder="请选择发货日期">
                    </el-date-picker>
                  </el-form-item>

                  <el-form-item label="交货日期" prop="jiaohuoDate">
                    <el-date-picker style="width: 100%;" clearable v-model="form.jiaohuoDate" type="date"
                      value-format="yyyy-MM-dd" placeholder="请选择交货日期">
                    </el-date-picker>
                  </el-form-item>
                  <el-form-item label="经理及电话" prop="jingli">
                    <el-input v-model="form.jingli" placeholder="请输入业务经理及电话" />
                  </el-form-item>
                  <el-form-item label="收货地址" prop="address">
                    <el-input v-model="form.address" placeholder="请输入收货地址" />
                  </el-form-item>
                  <el-form-item label="发运方式" prop="shipType">
                    <el-input v-model="form.shipType" placeholder="请输入发运方式" />
                  </el-form-item>
                  <el-form-item label="备注" prop="remark">
                    <el-input v-model="form.remark" placeholder="请输入备注" />
                  </el-form-item>
                </el-form>
              </el-card>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="24">
              <el-card class="box-card" style="margin-left: 10px;margin-top: 10px;">
                <el-row>
                  <el-col :span="24">
                    <div style="margin: 5px;">
                      <el-form :model="queryParams2" ref="queryForm" size="small" v-show="showSearch" :inline="true"
                        label-width="98px">
                        <el-form-item label="订单编号" prop="projectNo">
                          <el-input v-model="queryParams2.proNo" placeholder="请输入订单编号" size="mini" clearable
                            style="width:150px" @keyup.enter.native="handleQuery" />
                        </el-form-item>
                        <el-form-item label="产品编码" prop="nos">
                          <el-input v-model="queryParams2.nos" placeholder="请输入产品编码" size="mini" clearable
                            style="width:150px" @keyup.enter.native="handleQuery" />
                        </el-form-item>
                        <el-form-item label="产品名称" prop="name">
                          <el-input v-model="queryParams2.name" placeholder="请输入产品名称" size="mini" clearable
                            style="width:150px" @keyup.enter.native="handleQuery" />
                        </el-form-item>
                        <el-form-item label="产品型号" prop="models">
                          <el-input v-model="queryParams2.models" placeholder="请输入产品型号" size="mini" clearable
                            style="width:150px" @keyup.enter.native="handleQuery" />
                        </el-form-item>
                        <el-form-item>
                          <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery2">搜索
                          </el-button>
                          <el-popconfirm :title="`确认批量删除数据项？`" @confirm="handleDelete({})" style="margin-left: 10px;">
                            <el-button icon="el-icon-delete" size="mini" slot="reference" type="danger"
                              :disabled="multiple2" v-hasPermi="['develop:ProjectBaseInfo:remove']">删除
                            </el-button>
                          </el-popconfirm>
                        </el-form-item>
                        <el-form-item label="已勾选合计" prop="goodModel" v-if="selectedRowsFahuoMingxi.length > 0">
                          <span> {{selectedRowsFahuoMingxi.reduce((acc, row) => acc + row.shuliang, 0)}}</span>
                        </el-form-item>
                      </el-form>
                    </div>
                  </el-col>
                </el-row>

                <el-table :data="columns2" ref="dragTable" row-key="id" v-loading="loading2" show-summary
                  :summary-method="getSummaries" @selection-change="handleSelectionChangeFahuoMingxi"
                  @sort-change="handleSortChange1" max-height="550">
                  <el-table-column type="selection" width="50" align="center" fixed="left" />
                  <el-table-column label="序号" align="center" type="index" width="50" fixed="left" />
                  <el-table-column label="买方" align="center" prop="params.customName" />
                  <el-table-column sortable label="订单编号" align="center" prop="proNo" />
                  <el-table-column sortable label="工程名称" align="center" prop="params.gongchengName" />
                  <el-table-column sortable label="产品编码" align="center" prop="nos" />
                  <el-table-column sortable label="产品名称" align="center" prop="name" width="200" show-overflow-tooltip />
                  <el-table-column sortable label="产品型号" align="center" prop="models" show-overflow-tooltip />
                  <el-table-column label="产品单位" align="center" prop="danwei" width="50" />
                  <el-table-column label="产品单价" align="center" prop="danjian" width="60" />
                  <el-table-column label="发货数量" align="center" prop="shuliang" width="60" />
                  <el-table-column label="业务员" align="center" prop="saleman" width="60" />
                  <el-table-column label="备注" align="center" prop="remark" show-overflow-tooltip />
                  <el-table-column align="center" class-name="small-padding fixed-width" label="操作" width="80">
                    <template slot-scope="scope">
                      <el-button size="mini" type="text" icon="el-icon-edit"
                        @click="choseGoodsFahuo(scope.row)">选用产品</el-button>
                      <el-button size="mini" type="text" icon="el-icon-search"
                        @click="choseGoodsDeatil(scope.row)">选用明细</el-button>
                      <el-popconfirm :title="`确认删除 ` + scope.row.name + ` 数据项？`" @confirm="handleDelete(scope.row)"
                        style="margin-left: 10px;">
                        <el-button icon="el-icon-delete" size="mini" slot="reference" type="text"
                          v-hasPermi="['develop:ProjectBaseInfo:remove']">删除
                        </el-button>
                      </el-popconfirm>
                    </template>
                  </el-table-column>
                </el-table>
              </el-card>
            </el-col>
          </el-row>
        </el-col>
      </el-row>
    </div>
    <div slot="footer" class="dialog-footer">
      <el-button type="primary" @click="submitFormFahuodan">保 存 发 货 单</el-button>
      <el-button @click="cancel">取 消</el-button>
    </div>
    <choseGoods-fahuo-form-list @ok="getList" ref="choseGoodsFahuoFormList"></choseGoods-fahuo-form-list>
    <choseGoodsDeatil-form-list ref="choseGoodsDeatilFormList" @ok="getList"></choseGoodsDeatil-form-list>
  </el-dialog>
</template>

<script>
import {
  getAction,
  addAction,
  getById,
  deleteAction,
  updateAction, accAdd
} from '@/api/manage';
import moment from 'moment';
import ChoseGoodsFahuoFormList from '@/views/develop/goodsSaleMaterial/module/ChoseGoodsFahuoFormList'
import ChoseGoodsDeatilFormList from '@/views/develop/goodsSaleMaterial/module/ChoseGoodsDeatilFormList'

export default {
  name: "LvFahuoChooseForm",
  dicts: ['goods_customer', 'yifahuo_status'],
  components: {
    ChoseGoodsFahuoFormList,
    ChoseGoodsDeatilFormList
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      loading2: false,
      activeName: "first",
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        kehuId: [{
          required: true,
          message: "买方不能为空",
          trigger: "blur"
        }],
        /*fahuoDate: [{
          required: true,
          message: "发货日期不能为空",
          trigger: "blur"
        }],*/
      },
      total: 0,
      total2: 0,
      // 入库信息管理表格数据
      dataList: [],
      columns: [],
      columns2: [],
      columnsLinkman: [],
      showSearch: true,
      projectNos: [],
      queryParams: {
        pageNum: 1,
        pageSize: 50,
        goodsCode: null,
        goodsName: null,
        goodModel: null,
        brand: null,
        projectName: null,
        projectNo: [],
        isfahuo: "0",
        isclose: "0",
        params: {
        },
        customerCode: null,
        createName: null,
        salesmanName: null,
        orderDate: null,
        companyName: null,
        customName: null,
        deliveryPerson: null,
        orderByColumn: "a.sort",
        isAsc: "asc",
      },
      queryParams2: {
        pageNum: 1,
        pageSize: 1000,
        params: {},
        id: null,
        name: null,
        model: null,
        brand: null,
        status: null,
        customerCode: null,
        createName: null,
        salesmanName: null,
        orderDate: null,
        createBy: this.$store.getters.name,
      },
      queryParamsLinkman: {
        pageNum: 1,
        pageSize: 20000,
        customId: null,
        customerCode: null,
        createName: null,
        salesmanName: null,
        orderDate: null,
        name: null,
        params: {},
      },
      url: {
        listSendNotZero: '/goodsSale/goodsSale/listSendNotZero',
        list2: '/lvYifahuomingxi/lvYifahuomingxi/list',
        getById: '/lvYifahuo/lvYifahuo/',
        insertSendDetailFormGoodsSale: '/lvYifahuomingxi/lvYifahuomingxi/insertSendDetailFormGoodsSale',
        addZancun: '/lvYifahuo/lvYifahuo/addZancun',
        editDaitijiao: '/lvYifahuo/lvYifahuo/editDaitijiao',
        removeSendDetail: '/lvYifahuomingxi/lvYifahuomingxi/removeSendDetail/',
        listLinkman: '/goodsShouhuoren/goodsShouhuoren/list',
      },
      fahuoId: null,
      selectedRowsGoodsSale: [],
      selectedRowsFahuoMingxi: [],
      multiple2: true,
      ids2: [],
      single2: [],
      orderList: [],
      selected: null,
      options3: [],
      loading3: false,
      list: [] // 假设这是从服务器获取的完整数据列表
    };
  },
  created() {
    this.getOrderList();
  },
  methods: {
    async search(queryString) {
      this.loading3 = true;
      if (queryString) {
        try {
          let params = {
            // "pageSizeZero": true,
            "pageNum": 1,
            "pageSize": 20,
            "code": queryString

          };
          getAction("/projectBaseInfo/projectBaseInfo/list", params).then(response => {
            this.options3 = response.rows;
            this.loading3 = false;
          });

        } catch (error) {
          console.error('Error fetching data:', error);
          this.loading3 = false;
        }
      } else {
        this.options3 = [];
        this.loading3 = false;
      }
    },
    choseGoodsDeatil(row) {
      this.$refs.choseGoodsDeatilFormList.show(row, "2");
    },
    choseGoodsFahuo(row) {
      this.$refs.choseGoodsFahuoFormList.showRukuGoods(row);
    },
    selectCustomerQuery(value) {
      // this.form.kehuId = value;
      this.queryParams2.params['kehuId'] = value;
      this.getList();
      // this.selectCustomer(value);
      this.handleQuery()
    },

    selectCustomer(value) {
      let that = this;
      that.queryParams2.params['kehuId'] = value;
      // that.getList2();
      that.$nextTick(() => {
        let arr = that.$refs.myselectCustomer;
        for (let i = 0; i < arr.length; i++) {
          if (arr[i].currentValue == value) {
            that.form.kehuName = arr[i].label;
            that.queryParamsLinkman.customId = value;
            getAction(this.url.listLinkman, this.queryParamsLinkman).then(response => {
              this.columnsLinkman = response.rows;
            });
          }
        }
        that.form.linkman = '';
        that.form.linktel = '';
        that.form.jingli = '';
        that.form.address = '';
      })
    },
    selectShouhuoren(value) {
      let that = this;
      that.$nextTick(() => {
        let arr = that.$refs.myselectShouhuoren;
        for (let i = 0; i < arr.length; i++) {
          if (arr[i].currentValue == value) {
            that.form.linkman = value.shouhuoren;
            that.form.linktel = value.shouhuotel;
            that.form.jingli = value.jingli;
            that.form.address = value.address;
          }
        }
      })
    },
    updateTotleCost(row) {
      let that = this;
      if (row.shengyu && row.goodsBuyPrice) {
        let totleCost = that.functionNumberMul(row.shengyu, row.goodsBuyPrice);
        that.$set(row, "goodsBuyTotal", totleCost);
      }
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        delFlag: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        remark: null,
        nos: null,
        name: null,
        jiaohuoDate: null,
        linkman: null,
        linktel: null,
        address: null,
        status: "0",
        state: "0",
        jingli: null,
        kehuId: null,
        kehuName: null,
        taxNo: null,
        taxCode: null,
        taxDate: null,
        taxMoney: null,
        taxShengyu: null,
        taxAllmoeny: null,
        allMoney: null,
        shengyu: null,
        yihui: null
      };
      this.resetForm("form");
    },
    getList() {
      this.loading = true;
      this.queryParams.params["projectNos"] = this.projectNos;
      getAction(this.url.listSendNotZero, this.queryParams).then(response => {
        let res = response.rows;
        this.columns = res;
        for (let i = 0; i < this.columns.length; i++) {
          this.columns[i].sendCount = this.columns[i].fahuoShengyu;
        }
        this.total = response.total;
        this.loading = false;
      });
    },
    getList2() {
      this.loading2 = true;
      getAction(this.url.list2, this.queryParams2).then(response => {
        this.columns2 = response.rows;
        this.total2 = response.total;
        this.loading2 = false;
      });
    },
    /** 排序触发事件 */
    handleSortChange(column, prop, order) {
      this.queryParams.orderByColumn = column.prop;
      this.queryParams.isAsc = column.order;
      this.handleQuery();
    },
    /** 排序触发事件 */
    handleSortChange1(column, prop, order) {
      this.queryParams2.orderByColumn = column.prop;
      this.queryParams2.isAsc = column.order;
      this.handleQuery2();
    },

    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 搜索按钮操作 */
    handleQuery2() {
      this.queryParams2.pageNum = 1;
      this.getList2();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.queryParams.params = {};
      this.projectNos = []
      this.resetForm("queryForm");
      this.handleQuery();
    },

    // 多选框选中数据
    handleSelectionChangeGoodsSale(selection) {
      this.dataList = selection;
      this.selectedRowsGoodsSale = selection;
      this.ids = selection.map(item => item.id)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },

    // 多选框选中数据
    handleSelectionChangeFahuoMingxi(selection) {
      this.selectedRowsFahuoMingxi = selection;
      this.ids2 = selection.map(item => item.id)
      this.single2 = selection.length !== 1
      this.multiple2 = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加发货";
      this.loading = false;
      this.queryParams2.status = '0';
      this.queryParams2.fahuoId = null;
      this.getList()
      this.getList2()
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id;
      this.fahuoId = row.id;
      this.queryParams2.fahuoId = row.id;
      this.queryParams2.status = null;
      this.queryParams2.createBy = null;
      getById(this.url.getById, id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改出货22通知单";
        this.getList();
        this.getList2();
      });
    },
    /** 提交按钮 */
    submitFormFahuodan() {
      // console.log(this.form.kehuId);
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (!this.columns2.length) {
            this.$modal.msgError("请选择一条记录");
          } else {
            this.form.columns = this.columns2;
            addAction(this.url.addZancun, this.form).then(response => {
              this.$modal.msgSuccess("操作成功");
              this.open = false;
              this.getList2()
              this.$emit('ok');
            });
          }
        }
      });
    },
    submitForm() {
      let that = this;
      const ids = this.ids;
      const allEqual = arr => arr.every(val => val === arr[0]);
      const customId = []
      for (var i in ids) {
        customId.push(this.columns.find(item => item.id == ids[i]).order.customId)
      }
      const customName = []
      for (var i in ids) {
        customName.push(this.columns.find(item => item.id == ids[i]).order.customName)
      }
      console.log(customName, allEqual(customName), 'customNamecustomNamecustomNamecustomName');
      if (ids == null || ids == '' || ids == 'undefined') {
        that.$modal.msgError("请选择一条记录");
        // alert("请选择一条记录");
      } else if (!allEqual(customId)) {
        that.$modal.msgError("多买家信息不一致，请检查");
      } else {
        that.$refs["formList"].validate(valid => {
          if (valid) {
            const parmas = Object.assign({});
            parmas.goodsSaleList = that.dataList;
            that.form.kehuId = that.columns[0].kehuId
            that.form.kehuName = that.columns[0].kehuName
            parmas.fahuoId = that.fahuoId;
            addAction(that.url.insertSendDetailFormGoodsSale, parmas).then(response => {
              that.$modal.msgSuccess("添加成功");
              that.handleQuery();
              that.handleQuery2();
              that.$emit('ok');
              that.form.kehuName = customName[0];
              that.form.kehuId = customId[0];
              that.form.linkman = '';
              that.form.linktel = '';
              that.form.jingli = '';
              that.form.address = '';
            });
          }
        });
      }
    },
    handleDelete(row) {
      const ids = row.id || this.ids2;
      deleteAction(this.url.removeSendDetail, ids).then(response => {
        this.$modal.msgSuccess("删除成功");
        this.handleQuery();
        this.handleQuery2();
      }).catch(() => {
      });
    },


    getSummaries(param) {
      const { columns, data } = param;
      const sums = [];
      columns.forEach((column, index) => {
        if (index === 0) {
          sums[index] = "";
          return;
        }
        const values = data.map((item) => Number(item[column.property]));
        // 只合计amount1和amount3，想合并哪些列就在这里指定
        if (column.property === "fahuoShengyu" || column.property === "sendCount" || column.property === "shuliang" || column.property === "orderCount" || column.property == "danjian") {
          sums[index] = values.reduce((prev, curr) => {
            const value = Number(curr);
            if (!isNaN(value)) {
              return accAdd(prev, curr);
            } else {
              return prev;
            }
          }, 0);
        }
      });
      return sums;
    },

    getOrderList() {
      let params = {
        "pageSizeZero": true
      };
      getAction("/projectBaseInfo/projectBaseInfo/list", params).then(response => {
        this.orderList = response.rows;
      });
    },


  }
};
</script>
